﻿using Microsoft.VisualStudio.TestTools.UnitTesting;
using NoMvvm.TDD;
using System;

namespace NoMvvm.UnitTests
{
    /// <summary>
    /// This is the craziest set of tests I've ever written in my life...
    /// </summary>
    [TestClass]
    public class BlobTest
    {
        private class SubBlob : Blob
        {
            public int Add(int x, int y)
            {
                return x + y;
            }

            public string Add(string x, string y)
            {
                return x + y;
            }
        }

        [TestMethod]
        public void Get_Property()
        {
            dynamic blob = new Blob();
            dynamic result = blob.I.Can.Get.Any.Property.I.Want.And.It.Wont.Blow.Up;
        }

        [TestMethod]
        public void Set_Property()
        {
            dynamic blob = new Blob();
            dynamic result = blob.I.Can.Set.Any.Property.I.Want.And.It.Wont.Blow = "Up";
        }

        [TestMethod]
        public void Call_Method()
        {
            dynamic blob = new Blob();
            dynamic result = blob.I.Can.Call.Any.Method.I.Want.And.It.Wont.Blow.Up();
        }

        [TestMethod]
        public void Call_Method_With_Parameters()
        {
            dynamic blob = new Blob();
            dynamic result = blob.I.Can.Call.Any.Method.I.Want.And.It.Wont.Blow.Up("And", "Any", "Parameter", "I", "Want", 1, 2, 3, 44.99m);
        }

        [TestMethod]
        public void Get_Index()
        {
            dynamic blob = new Blob();
            dynamic result = blob["I"]["Can"]["Get"]["Indexes"]["All"]["Day"]["Like"]["It"]["Aint"]["No"]["Thang"];
        }

        [TestMethod]
        public void Set_Index()
        {
            dynamic blob = new Blob();
            blob["I"]["Can"]["Set"]["Indexes"]["All"]["Day"]["Like"]["It"]["Aint"]["No"] = "Thang";
        }

        [TestMethod]
        public void Cast()
        {
            dynamic blob = new Blob();

            int Int32 = blob;
            double Double = blob;
            float Float = blob;
            object Object = blob;
            Guid Guid = blob;
            DateTime DateTime = blob;
        }

        [TestMethod]
        public void Unary()
        {
            dynamic blob = new Blob();
            dynamic result;

            result = !blob;
            result = ++blob;
            result = --blob;
            result = blob++;
            result = blob--;
            result = blob += 1;
            result = blob -= 1;
            result = blob /= 2;
            result = blob *= 4;
            result = blob ^= true;
            result = blob |= true;
            result = blob &= false;
            result = blob %= 5;
        }

        [TestMethod]
        public void Binary()
        {
            dynamic thing1 = new Blob();
            dynamic thing2 = new Blob();
            dynamic result;

            result = thing1 + thing2;
            result = thing1 - thing2;
            result = thing1 / thing2;
            result = thing1 * thing2;
            result = thing1 | thing2;
            result = thing1 & thing2;
            result = thing1 ^ thing2;
            result = thing1 % thing2;
        }

        [TestMethod]
        public void Inheritance_Int()
        {
            dynamic blob = new SubBlob();
            int result = blob.Add(2, 2);
            Assert.AreEqual(4, result);
        }

        [TestMethod]
        public void Inheritance_String()
        {
            dynamic blob = new SubBlob();
            string result = blob.Add("He", "llo");
            Assert.AreEqual("Hello", result);
        }

        [TestMethod]
        public void Inheritance_No_Match()
        {
            dynamic blob = new SubBlob();
            int result = blob.Add(1, "llo");
            Assert.AreEqual(default(int), result);
        }
    }
}
